import router from './router'
import store from './store'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css' // Progress 进度条样式
// import {getToken} from '@/utils/auth' // 验权
import {setTitle} from '@/utils/util' // 设置浏览器头部标题

// const loginPage = '/login';
// const loginPage = '/org';

// permission judge function
// function hasPermission(roles, permissionRoles) {
//   if (roles.indexOf('admin') >= 0) return true // admin permission passed directly
//   if (!permissionRoles) return true
//   return roles.some(role => permissionRoles.indexOf(role) >= 0)
// }

// const whiteList = [loginPage, '/register', '/404', '/401']
//
// whiteList.push('/bankAd', '/bankAd/translationPage', '/downloadPSDB')

// '/org/order/list', '/org/old/list', '/org/order/case', '/people', '/people/device', '/people/detail'] // 不重定向白名单
// router.beforeEach((to, from, next) => {
//   NProgress.start()
//   if (getToken()) {
//     /* has token*/
//     if (to.path === loginPage) {
//       next({path: '/'})
//       NProgress.done() // if current page is dashboard will not trigger	afterEach hook, so manually handle it
//     } else {
//       next()
//     }
//   } else {
//     if (whiteList.indexOf(to.path) !== -1) {
//       next()
//     } else {
//       next(loginPage)
//       NProgress.done()
//     }
//   }
// })

router.afterEach((to, form) => {
  NProgress.done() // 结束Progress
  setTimeout(() => {
    const browserHeaderTitle = to.meta.title || store.getters.browserHeaderTitle
    setTitle(browserHeaderTitle)
  }, 0)
})
